package com.wangyg.flourfactory.controller;

import com.wangyg.flourfactory.model.FlourFactory;
import com.wangyg.flourfactory.service.IFlourFactorySMO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by wangyg6 on 2019/5/14 15:10.
 */
@RestController("/")
public class FlourController {

	@Autowired
	IFlourFactorySMO factorySMO;

	@PostMapping("flourFactory")
	public FlourFactory crateFactory(@RequestBody FlourFactory flourFactory) {
		FlourFactory factory = FlourFactory.builder().factId(flourFactory.getFactId())
				.phoneNum(flourFactory.getPhoneNum()).addr(flourFactory.getAddr()).build();
		return factorySMO.createFlourFactory(factory);
	}

	@GetMapping("flourFactory")
	public Integer getFlourNum(@RequestParam("factId") Integer factId) {
		return factorySMO.getFlourCount(factId);
	}

}
